package com.foxzzz.array;


import com.foxzzz.base.ArrayUtil;

import java.util.*;

public class Solution128 {

    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        int max = 0;

        for (int num : nums) {
            int current = 0;
            int index = num;
            while (set.contains(index)) {
                index++;
                current++;
                max = max < current ? current : max;
            }
        }

        return max;
    }

    public static void main(String[] args) {
        Solution128 solution128 = new Solution128();
        System.out.println(solution128.longestConsecutive(ArrayUtil.generator(100, 4, 200, 1, 3, 2)));
    }
}
